/*
 * Copyright (C) 2012 NAJAHI Saïd (KyouJin-SaMa)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.ksama.sshbasic.model.dao;

import java.util.List;
import org.springframework.orm.hibernate3.HibernateTemplate;

/**
 *
 * @author NAJAHI Saïd (KyouJin-SaMa)
 */
public class GenericDAO<T> {

    private HibernateTemplate hibernateTemplate;
    private final Class<T> entityClass;

    public GenericDAO(Class<T> entityClass, HibernateTemplate hibernateTemplate) {
        this.entityClass = entityClass;
        this.hibernateTemplate = hibernateTemplate;
    }

    public void save(T t) {
        hibernateTemplate.saveOrUpdate(t);

    }

    public void delete(T t) {
        hibernateTemplate.delete(t);

    }

    public List<T> getAll() {
        return (List<T>) hibernateTemplate.find("from "
                + entityClass.getName());
    }

    public T selectById(String id) {
        return hibernateTemplate.get(entityClass, id);
    }
}
